package com.xyazm.coupon.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xyazm.common.api.CommonPage;
import com.xyazm.common.api.CommonVO;
import com.xyazm.coupon.domain.param.QueryCouponListParam;
import com.xyazm.coupon.domain.param.resource.ListCouponResourceParam;
import com.xyazm.coupon.domain.vo.CouponResourceVO;
import com.xyazm.coupon.entity.CouponResourceDO;
import com.xyazm.coupon.mapstruct.ApiMapstruct;
import com.xyazm.coupon.mapstruct.CouponResourceMapstruct;
import com.xyazm.coupon.service.ICouponResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CouponResourceApi implements ICouponResourceApi {

    @Autowired
    private ICouponResourceService couponResourceService;


    @Override
    public CommonVO<CommonPage> list(QueryCouponListParam param) {
        ListCouponResourceParam couponListDTO = ApiMapstruct.INSTANCE.convertCouponListDTO(param);
        Page<CouponResourceDO> page = couponResourceService.list(couponListDTO);
        List<CouponResourceVO> vos = CouponResourceMapstruct.INSTANCE.couponResourceDTOToVO(page.getRecords());
        return CommonVO.success(CommonPage.convertPage(page.getTotal(),vos));
    }
}
